import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vite.dev/config/  这里是配置跨域的
export default defineConfig({
  plugins: [vue()],
  base: '/storeadmin/', // 与你的部署路径匹配
  server: {
    proxy: {
      '/api': {
        target: 'https://zhjh168.com',
        changeOrigin: true,
        secure: false,
        ws: true,
        rewrite: (path) => path,
        configure: (proxy, options) => {
          proxy.on('error', (err, req, res) => {
            // console.log('proxy error', err);
          });
          proxy.on('proxyReq', (proxyReq, req, res) => {
            proxyReq.setHeader('Origin', 'https://zhjh168.com');
            proxyReq.setHeader('Referer', 'https://zhjh168.com');
          });
        }
      },
      '/dashscope': {
        target: 'https://dashscope.aliyuncs.com',
        changeOrigin: true,
        secure: true,
        rewrite: (path) => path.replace(/^\/dashscope/, ''),
        configure: (proxy, options) => {
          proxy.on('proxyReq', (proxyReq, req, res) => {
            // 保持原有的请求头
            console.log('代理通义千问API请求:', req.url);
          });
        }
      }
    }
  }
})
